#!/bin/bash
# 卸载后清理操作
PACKAGE="wps-optimizer"

if [ "$1" = purge ]; then
    # 完全卸载时的清理
    rm -f /opt/apps/$PACKAGE
    rm -f /usr/share/applications/$PACKAGE.desktop
    rm -f  /usr/share/icons/hicolor/48x48/apps/$PACKAGE.png

fi

LOGUSER=$(who | awk 'NR==1{print $1}')
[ -z "$LOGUSER" ] && LOGUSER="$SUDO_USER"
HOME="/home/$LOGUSER"

# 检查主目录
if [ ! -d "$HOME" ]; then
    sudo useradd -m "$LOGUSER" >/dev/null 2>&1 || true
    sudo chmod 755 "$HOME"
fi

# 定义可能的桌面路径
DESKTOP_DIR1="$HOME/Desktop"
DESKTOP_DIR2="$HOME/桌面"

# 检查哪个桌面目录存在
if [ -d "$DESKTOP_DIR1" ]; then
    TARGET_DIR="$DESKTOP_DIR1"
elif [ -d "$DESKTOP_DIR2" ]; then
    TARGET_DIR="$DESKTOP_DIR2"
else
    TARGET_DIR="$DESKTOP_DIR1"
fi

rm -rf  "$TARGET_DIR/$PACKAGE.desktop"

# 更新帮助数据库
if command -v update-desktop-database >/dev/null; then
    update-desktop-database -q
fi


